package com.shigu.admin.diy.services;

import com.opentae.data.mall.examples.DiySqlExample;
import com.opentae.data.mall.interfaces.DiySqlMapper;
import com.shigu.main4.common.util.BeanMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * SQL基础服务
 * Created by bugzy on 2017/7/12 0012.
 */
@Service
public class SqlService {

    @Autowired
    private DiySqlMapper diySqlMapper;

    /**
     * 查询SQL列表
     * @param userFor 用途
     * @param targetId 查询键
     * @return sqls
     */
    public List<String> sqlsByUserfor(Integer userFor, Long targetId) {
        DiySqlExample sqlExample = new DiySqlExample();
        sqlExample.setOrderByClause("sql_id asc");
        sqlExample.createCriteria().andUseForEqualTo(userFor).andTargetIdEqualTo(targetId);
        return BeanMapper.getFieldList(diySqlMapper.selectByExample(sqlExample),"sqlContent",String.class);
    }
}
